package pkg

import (
	"custom-oracledb-exporter/config"
	"log"
	"os"
)

func InitLogger(path string) {
	if !config.C.Logger.Enable {
		log.SetOutput(os.Stdout)
		log.SetPrefix("[exporter] ")
		return
	}
	if path == "" {
		path = "app.log"
	}
	logFile, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
	if err != nil {
		log.Fatal(err.Error())
	}
	log.SetOutput(logFile) // 将文件设置为log输出的文件
	log.SetPrefix("[exporter] ")
	log.SetFlags(log.LstdFlags | log.Lshortfile | log.LUTC)
}
